package com.ddshuai.easy;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述 新通教育
 *
 * @author ddshuai
 * @date 2018-12-14 17:09
 **/
public class BinaryTreePaths {

    List<String> stringList = new ArrayList<>(1000);

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public List<String> binaryTreePaths(TreeNode root) {
        if (root == null) {
            return stringList;
        }
        addPath(root, root.val + "");
        return stringList;
    }

    private void addPath(TreeNode root, String parent) {
        if (root != null) {
            if (root.left == null && root.right == null) {
                stringList.add(parent);
            } else {
                if (root.left != null) {
                    addPath(root.left, parent + "->" + root.left.val);
                }
                if (root.right != null) {
                    addPath(root.right, parent + "->" + root.right.val);
                }
            }
        }
    }
}
